// Copyright(c) 2011 Matthew McMullan, Jorel Lalicki and Mike Heise, Jorel Lalicki and Mike Heise. See copying.txt for details.

#ifndef __agml_slices_h__
#define __agml_slices_h__

// make sure that this file is never included directly
#ifndef __agml_agml_h__
#error "Include AGML from agml.h only. This file is not a valid entry point for the library."
#endif

#include "pages.h"
#include "chunks.h"

namespace agml {
	namespace _memory {
		class _slice_allocator {
		public:
			void *alloc(u32 number) {
				return chunk_allocator.alloc(number);
			}
			void free(void *mem, u32 number) {
				chunk_allocator.free(mem,number);
			}
			u32 resize(void *&mem, u32 size, u32 /*min*/, u32 max) {
				void *newmem = chunk_allocator.alloc(max);
				u32_fast cpy = (max<size?max:size)*2;
				for (u32_fast i = 0; i<cpy; ++i) {
					((u64*)newmem)[i] = ((u64*)mem)[i];
				}
				mem = newmem;
				return max;
			}
		};
	}
	_memory::_slice_allocator slice_allocator;
}

#endif
